//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class PageSetup : IOfficeXmlSerializable
    {
        private bool _blackAndWhite;
        private int _copies;
        private bool _draft;
        private int _firstPageNumber;
        private int _horizontalDpi = 600;
        private PageSetupOrientation _orientation;
        private int _paperSize = 1;
        private bool _useFirstPageNumber;

        private int _verticalDpi = 600;

        public int Copies
        {
            get { return _copies; }
            set { _copies = value; }
        }

        public int VerticalDpi
        {
            get { return _verticalDpi; }
            set { _verticalDpi = value; }
        }


        public int HorizontalDpi
        {
            get { return _horizontalDpi; }
            set { _horizontalDpi = value; }
        }


        public bool UseFirstPageNumber
        {
            get { return _useFirstPageNumber; }
            set { _useFirstPageNumber = value; }
        }


        public bool Draft
        {
            get { return _draft; }
            set { _draft = value; }
        }


        public bool BlackAndWhite
        {
            get { return _blackAndWhite; }
            set { _blackAndWhite = value; }
        }


        public int PaperSize
        {
            get { return _paperSize; }
            set { _paperSize = value; }
        }

        public int FirstPageNumber
        {
            get { return _firstPageNumber; }
            set { _firstPageNumber = value; }
        }

        public PageSetupOrientation Orientation
        {
            get { return _orientation; }
            set { _orientation = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("pageSetup"))
            {
                PaperSize = c.GetOptionalInteger("paperSize", 1);
                FirstPageNumber = c.GetOptionalInteger("firstPageNumber", 1);
                Orientation = c.GetOptionalEnum("orientation", PageSetupOrientation.Default);
                BlackAndWhite = c.GetOptionalBoolean("blackAndWhite", false);
                Draft = c.GetOptionalBoolean("draft", false);
                UseFirstPageNumber = c.GetOptionalBoolean("useFirstPageNumber", false);
                HorizontalDpi = c.GetOptionalInteger("horizontalDpi", 600);
                    //\\in theory, should be uint but is int in practice
                VerticalDpi = c.GetOptionalInteger("verticalDpi", 600);
                Copies = c.GetOptionalInteger("copies", 1);
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("pageSetup"))
            {
                c.SetOptionalInteger("paperSize", PaperSize, 1);
                c.SetOptionalInteger("firstPageNumber", FirstPageNumber, 1);
                c.SetOptionalEnum("orientation", Orientation, PageSetupOrientation.Default);
                c.SetOptionalBoolean("blackAndWhite", BlackAndWhite, false);
                c.SetOptionalBoolean("draft", Draft, false);
                c.SetOptionalBoolean("useFirstPageNumber", UseFirstPageNumber, false);
                c.SetOptionalInteger("horizontalDpi", HorizontalDpi, 600);
                c.SetOptionalInteger("verticalDpi", VerticalDpi, 600);
                c.SetOptionalInteger("copies", Copies, 1);
            }
        }

        #endregion
    }
}